package com.tc.converter;

import com.tc.entity.TestConverterBean1;
import com.tc.entity.TestConverterBean2;
import com.tc.entity.TestMapperBean1;
import com.tc.entity.TestMapperBean2;
import com.tc.support.BeanMapper;
import lombok.extern.java.Log;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MappingContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Log
@Component
public class OrikaCustomMapper extends CustomMapper<TestConverterBean1, TestConverterBean2> {

    @Autowired
    private BeanMapper beanMapper;

    @Override
    public void mapAtoB(TestConverterBean1 a, TestConverterBean2 b, MappingContext context) {
        b.setAge(a.getAge());
        b.setName(a.getName());
        b.setAmount2(beanMapper.mapAsList(a.getAmount1(),TestMapperBean2.class));
        log.info("A to B");
    }

    @Override
    public void mapBtoA(TestConverterBean2 b, TestConverterBean1 a, MappingContext context) {
        a.setAge(b.getAge());
        a.setName(b.getName());
        a.setAmount1(beanMapper.mapAsList(b.getAmount2(),TestMapperBean1.class));
        log.info("B to A");
    }

};